import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: 'user',
    meta: { title: '用户管理', icon: 'user' },
    children: [
      {
        path: 'list',
        name: 'Table',
        component: () => import('@/views/userList/index'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'tinymce',
        name: 'Tinymce',
        component: () => import('@/views/tinymce/index'),
        meta: { title: 'tinymce', icon: 'tree' }
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/index',
    name: 'article',
    meta: {
      title: '文章管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/articleList/index'),
        meta: { title: '文章列表' }
      }
    ]
  },
  {
    path: '/cookie',
    component: Layout,
    redirect: '/cookie/index',
    name: 'cookie',
    meta: {
      title: '菜品管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/cookieList/index'),
        meta: { title: '菜品列表' }
      }
    ]
  },
  {
    path: '/chart',
    component: Layout,
    redirect: '/chart/index',
    name: 'chart',
    meta: {
      title: '图表管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/chartList/index'),
        meta: { title: '组件管理' }
      },
	  {
	    path: 'templete',
	    component: () => import('@/views/chartList/index'),
	    meta: { title: '模板管理' }
	  }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
